#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QKeyEvent>
#include <QTimer>
#include <QDebug>
#include "../utils/fsm.h"

class Displayer: public fsmlite::fsm<Displayer>
{
public:
    // 状态集
    enum states { StateFree, StateCar, StateCheck };

    // 事件
    struct EventCome {};
    struct EventIn {};
    struct EventCheck {};
    struct EventLeave {};

    // 初始状态
    Displayer(state_type init_state = StateFree) : fsm(init_state) {}
private:
    // 事件产生的动作
    void actCome(const EventCome&)
    {
        qDebug() << "xx come";
    }
    void actIn(const EventIn&)
    {
        qDebug() << "xx in";
    }
    void actCheck(const EventCheck&)
    {
        qDebug() << "xx check";
    }
    void actLeave(const EventLeave&)
    {
        qDebug() << "xx leave";
    }

    // 状态迁移表
    using transition_table = table<
    mem_fn_row< StateFree,  EventCome,        StateCar,      &Displayer::actCome >,
    mem_fn_row< StateCar,   EventIn,          StateFree,     &Displayer::actIn >,
    mem_fn_row< StateFree,  EventCheck,       StateCheck,    &Displayer::actCheck >,
    mem_fn_row< StateCheck, EventLeave,       StateFree,     &Displayer::actLeave >
    >;


    friend class fsm; // base class needs access to transition_table
};

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    void switchWelcome();
    void switchFull();
    void switchFree();
    void switchCar();

    int init_signal();
    int signal(char *arg);
signals:
    int do_signal(char *arg);
public slots:
    int onMySignal(char *arg);
    void onTimeOut();

private:
    virtual void keyPressEvent(QKeyEvent *ev);
    Ui::MainWindow *ui;
    QTimer *timer;
    Displayer displayer;
};

#endif // MAINWINDOW_H
